/*     */ package com.iris.egrant.orm.hibernate;
/*     */ 
/*     */ import java.io.Serializable;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.collections.MapUtils;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.hibernate.SessionFactory;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.stereotype.Repository;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Repository
/*     */ public class DynSqlDao<T, PK extends Serializable>
/*     */   extends HibernateDao<T, PK>
/*     */ {
/*  26 */   protected Logger logger = LoggerFactory.getLogger(getClass());
/*     */ 
/*     */   
/*     */   public DynSqlDao() {}
/*     */ 
/*     */   
/*     */   public DynSqlDao(SessionFactory sessionFactory, Class<T> entityClass) {
/*  33 */     super(sessionFactory, entityClass);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void delete(String tableName, Map<String, Object> conditions) {
/*  45 */     if (MapUtils.isEmpty(conditions)) {
/*     */       return;
/*     */     }
/*  48 */     if (StringUtils.isBlank(tableName)) {
/*     */       return;
/*     */     }
/*     */     
/*  52 */     Iterator<Map.Entry<String, Object>> it = conditions.entrySet().iterator();
/*     */     
/*  54 */     StringBuffer sql = new StringBuffer();
/*  55 */     sql.append("delete from " + tableName);
/*  56 */     sql.append("  where 1=1 ");
/*     */ 
/*     */ 
/*     */     
/*  60 */     while (it.hasNext()) {
/*  61 */       Map.Entry<String, Object> entry = it.next();
/*  62 */       String key = entry.getKey();
/*  63 */       Object value = entry.getValue();
/*  64 */       if (StringUtils.isNotBlank(key)) {
/*  65 */         sql.append(" and " + key + "='" + value + "'");
/*     */       }
/*     */     } 
/*  68 */     update(sql.toString());
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void update(String tableName, Map<String, Object> modFields, Map<String, Object> conditions) {
/*  81 */     if (StringUtils.isBlank(tableName)) {
/*     */       return;
/*     */     }
/*  84 */     if (MapUtils.isEmpty(modFields) || MapUtils.isEmpty(conditions)) {
/*     */       return;
/*     */     }
/*  87 */     Iterator<Map.Entry<String, Object>> itModField = modFields.entrySet().iterator();
/*  88 */     Iterator<Map.Entry<String, Object>> itCondition = conditions.entrySet().iterator();
/*     */     
/*  90 */     StringBuffer sql = new StringBuffer();
/*  91 */     StringBuffer fields = new StringBuffer();
/*  92 */     sql.append("update " + tableName);
/*  93 */     sql.append(" set  ");
/*     */ 
/*     */     
/*  96 */     while (itModField.hasNext()) {
/*  97 */       Map.Entry<String, Object> entry = itModField.next();
/*  98 */       String key = entry.getKey();
/*  99 */       Object value = entry.getValue();
/* 100 */       if (StringUtils.isNotBlank(key)) {
/* 101 */         fields.append("," + key + "='" + value + "'");
/*     */       }
/*     */     } 
/* 104 */     if (fields.length() > 0) {
/* 105 */       sql.append(fields.substring(1));
/*     */     }
/* 107 */     sql.append("  where 1=1 ");
/* 108 */     while (itCondition.hasNext()) {
/* 109 */       Map.Entry<String, Object> entry = itCondition.next();
/* 110 */       String key = entry.getKey();
/* 111 */       Object value = entry.getValue();
/* 112 */       if (StringUtils.isNotBlank(key)) {
/* 113 */         sql.append(" and " + key + "='" + value + "'");
/*     */       }
/*     */     } 
/* 116 */     update(sql.toString());
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void save(String tableName, Map<String, Object> addFields) {
/* 127 */     if (StringUtils.isBlank(tableName)) {
/*     */       return;
/*     */     }
/* 130 */     if (MapUtils.isEmpty(addFields)) {
/*     */       return;
/*     */     }
/* 133 */     Iterator<Map.Entry<String, Object>> it = addFields.entrySet().iterator();
/* 134 */     StringBuffer sql = new StringBuffer();
/* 135 */     sql.append("insert into " + tableName);
/*     */     
/* 137 */     StringBuffer fields = new StringBuffer();
/* 138 */     StringBuffer values = new StringBuffer();
/*     */ 
/*     */     
/* 141 */     while (it.hasNext()) {
/* 142 */       Map.Entry<String, Object> entry = it.next();
/* 143 */       String key = entry.getKey();
/* 144 */       Object value = entry.getValue();
/* 145 */       if (StringUtils.isNotBlank(key)) {
/* 146 */         fields.append("," + key);
/* 147 */         values.append(",'" + value + "'");
/*     */       } 
/*     */     } 
/* 150 */     if (fields.length() > 0) {
/* 151 */       sql.append(" (" + fields.substring(1) + ") ");
/* 152 */       sql.append(" values (" + values.substring(1) + ")");
/* 153 */       update(sql.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void save(String tableName, Map<String, Object> addFields, String seqName) {
/* 165 */     if (StringUtils.isBlank(tableName)) {
/*     */       return;
/*     */     }
/* 168 */     if (MapUtils.isEmpty(addFields)) {
/*     */       return;
/*     */     }
/* 171 */     if (StringUtils.isBlank(seqName)) {
/*     */       return;
/*     */     }
/*     */     
/* 175 */     Iterator<Map.Entry<String, Object>> it = addFields.entrySet().iterator();
/* 176 */     StringBuffer sql = new StringBuffer();
/* 177 */     sql.append("insert into " + tableName);
/*     */     
/* 179 */     StringBuffer fields = new StringBuffer();
/* 180 */     StringBuffer values = new StringBuffer();
/*     */ 
/*     */     
/* 183 */     while (it.hasNext()) {
/* 184 */       Map.Entry<String, Object> entry = it.next();
/* 185 */       String key = entry.getKey();
/* 186 */       Object value = entry.getValue();
/* 187 */       if (StringUtils.isNotBlank(key)) {
/*     */         
/* 189 */         if ("seqNo".equalsIgnoreCase(key) && StringUtils.isBlank(value.toString())) {
/* 190 */           fields.append("," + key);
/* 191 */           values.append(",'" + getSeqNextVal(seqName) + "'"); continue;
/*     */         } 
/* 193 */         fields.append("," + key);
/* 194 */         values.append(",'" + value + "'");
/*     */       } 
/*     */     } 
/*     */     
/* 198 */     if (fields.length() > 0) {
/* 199 */       sql.append(" (" + fields.substring(1) + ") ");
/* 200 */       sql.append(" values (" + values.substring(1) + ")");
/* 201 */       update(sql.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public List query(String tableName, Map<String, Object> conditions) {
/* 216 */     if (MapUtils.isEmpty(conditions)) {
/* 217 */       return null;
/*     */     }
/* 219 */     if (StringUtils.isBlank(tableName)) {
/* 220 */       return null;
/*     */     }
/*     */     
/* 223 */     Iterator<Map.Entry<String, Object>> it = conditions.entrySet().iterator();
/*     */     
/* 225 */     StringBuffer sql = new StringBuffer();
/* 226 */     sql.append("select * from " + tableName);
/* 227 */     sql.append("  where 1=1 ");
/*     */ 
/*     */     
/* 230 */     while (it.hasNext()) {
/* 231 */       Map.Entry<String, Object> entry = it.next();
/* 232 */       String key = entry.getKey();
/* 233 */       Object value = entry.getValue();
/* 234 */       if (StringUtils.isNotBlank(key)) {
/* 235 */         sql.append(" and " + key + "='" + value + "'");
/*     */       }
/*     */     } 
/* 238 */     List list = queryForList(sql.toString());
/* 239 */     return list;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public List query(String tableName, String conditions) {
/* 254 */     if (StringUtils.isBlank(conditions)) {
/* 255 */       return null;
/*     */     }
/* 257 */     if (StringUtils.isBlank(tableName)) {
/* 258 */       return null;
/*     */     }
/* 260 */     StringBuffer sql = new StringBuffer();
/* 261 */     sql.append("select * from " + tableName);
/* 262 */     sql.append(" where 1=1 and " + conditions);
/* 263 */     List list = queryForList(sql.toString());
/* 264 */     return list;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public Long getSeqNextVal(String seqName) {
/* 275 */     String sql = "select " + seqName + ".nextval from dual";
/* 276 */     return Long.valueOf(queryForLong(sql));
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\orm\hibernate\DynSqlDao.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */